package Zoo.View.UserView;

import Zoo.Entity.UserEntity;
import Zoo.Handler.AddUserViewHandler;

import javax.swing.*;
import java.awt.*;

public class AddUserView extends JDialog {
    JPanel jPanel=new JPanel();
    JLabel nameLable =new JLabel("用户名");
    JTextField nameTxt=new JTextField();


    JLabel pwdLable =new JLabel("密码");
    JTextField pwdTxt=new JTextField();
    JLabel phoneLable =new JLabel("联系方式");
    JTextField phoneTxt=new JTextField();
    JButton addBtn =new JButton("添加");

    AddUserViewHandler addUserViewHandler;

    public AddUserView(UserView userView){
        super(userView,"添加用户信息",true);

        addUserViewHandler=new AddUserViewHandler(this);


        nameLable.setPreferredSize(new Dimension(80,30));
        jPanel.add(nameLable);
        nameTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(nameTxt);



        pwdLable.setPreferredSize(new Dimension(80,30));
        jPanel.add(pwdLable);
        pwdTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(pwdTxt);

        phoneLable.setPreferredSize(new Dimension(80,30));
        jPanel.add(phoneLable);
        phoneTxt.setPreferredSize(new Dimension(200,30));
        jPanel.add(phoneTxt);


        Container contentPane=getContentPane();
        contentPane.add(jPanel);
        //监听
        addBtn.addActionListener(addUserViewHandler);
        jPanel.add(addBtn);

        setSize(350,500);
        setLocationRelativeTo(null);
        //DISPOSE_ON_CLOSE：只销毁当前的窗体
        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        setResizable(false);
        setVisible(true);


    }

    public UserEntity buildUserEntity(){
        UserEntity userEntity =new UserEntity();


        userEntity.setUsername(nameTxt.getText());
        userEntity.setPwd(pwdTxt.getText());
        userEntity.setPhone(phoneTxt.getText());

        return userEntity;
    }


}
